﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics;
using System.IO;
using System.Windows.Navigation;
using System.Reflection;


namespace Awesome_Shutdown_Timer
{
    /// <summary>
    /// Interaction logic for wndAbout.xaml
    /// </summary>
    public partial class wndAbout : Window
    {
        public wndAbout()
        {
            InitializeComponent();

            // show version info
            lblAboutVersion.Content = Assembly.GetExecutingAssembly().GetName().Name + " " +
                Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "." +
                Assembly.GetExecutingAssembly().GetName().Version.MajorRevision.ToString() + "." +
                Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString() + " build " +
                Assembly.GetExecutingAssembly().GetName().Version.MinorRevision.ToString();
            // Get all Copyright attributes on this assembly
            object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
            lblAboutCopyright.Content = "Copyright " + ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace(" __alex", " ____alex");
        }

        //--------------------------------------------------

        public void ShowDialog(Window owner)
        {
            this.Owner = owner;
            this.ShowDialog();
        }

        //--------------------------------------------------

        public void Show(Window owner)
        {
            this.Owner = owner;
            this.Show();
        }

        //--------------------------------------------------

        public void hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            if (e.Uri.IsAbsoluteUri)
            {
                // open a webpage

                Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
            }
            else
            {
                // open a file

                string eula = wndMain.appPath + "\\" + e.Uri.OriginalString;
                if (!File.Exists(eula))
                {
                    System.Windows.MessageBox.Show("ERROR: License file \"" + e.Uri.OriginalString + "\" is missing!",
                        wndMain.appTitle,
                        MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                Process.Start(new ProcessStartInfo(eula));
            }

            e.Handled = true;
        }

        private void cmdOK_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
